#region license
# This file is part of Grawlix.
# 
# Grawlix is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version 3 of
# the License, or (at your option) any later version.
# 
# Grawlix is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public
# License along with Grawlix.  If not, see
# <http://www.gnu.org/licenses/>.
#endregion

"""The base class for GUI components."""

namespace Grawlix.Application.Gui
import Grawlix
import Grawlix.Meta
import Grawlix.Services.Rendering
import System

[Disposable]
abstract transient class Control:
"""Provides the main functionality for GUI components."""
	
	protected def constructor():
	"""Default constructor."""
		pass
	
	abstract def Render(device as IRenderDevice,
	                    area as Rect):
	"""
	Render the current control, including all children.
	Param device: The rendering device to use.
	Param area: The area the device is clipped to.
	"""
		pass
	
	virtual def OnKeyDown(code as int):
	"""
	Respond to a key being pressed.
	Param code: A game-dependent code triggered by keypress.
	Remarks:
		The default behavior is to call the parent
		control's OnKeyDown response. Call this base function
		if the event is not handled.
	"""
		if Parent != null:
			Parent.OnKeyDown(code)
	
	virtual def OnKeyUp(code as int):
	"""
	Respond to a key being pressed.
	Param code: A game-dependent code triggered by keypress.
	Remarks:
		The default behavior is to call the parent
		control's OnKeyUp response. Call this base function
		if the event is not handled.
	"""
		if Parent != null:
			Parent.OnKeyUp(code)
	
	virtual def OnCharacter(character as char):
	"""
	Respond to text input.
	Param character: A unicode code point.
	Remarks:
		The default behavior is to call the parent
		control's OnCharacter response. Call this base function
		if the event is not handled.
	"""
		if Parent != null:
			Parent.OnCharacter(character)
	
	virtual def MouseTest(position as Vector,
	                      bounds as Rect):
	"""
	Figure out which control is under the cursor.
	Param position:
		in: The position of the cursor.
		out: The bounds of the cursor the bounds.
	Param bounds:
		in: The bounds of this rect.
		out: The bounds of the target rect.
	Returns: The control under the cursor.
	Remarks: There should be no side-effects in this call.
		It should recurse down the control hierarchy.
	"""
		return self
	
	virtual def OnMouseEnter(position as Vector,
	                         bounds as Rect):
	"""
	Respond to the mouse entering this control.
	Param position: The position within the control.
	Param bounds: A bounding box enclosing the entire control.
	Remarks:
		Entering a subcontrol will invoke a leave event.
	"""
		pass
	
	virtual def OnMouseLeave(position as Vector,
	                         bounds as Rect):
	"""
	Respond to the mouse leaving the control.
	Param position: The last known position within the control.
	Param bounds: The last known bounding box enclosing the entire control.
	"""
		pass
	
	virtual def OnMouseMove(position as Vector,
	                        delta as Vector,
	                        bounds as Rect):
	"""
	Respond to the mouse being moved.
	Param position: The absolute position of the mouse.
	Param delta: The change from the last movement event.
	Param bounds: A bounding box enclosing the entire control.
	"""
		pass
	
	virtual def OnMouseWheel(position as Vector,
	                         ticks as int,
	                         bounds as Rect):
	"""
	Respond to the mouse wheel being moved.
	Param position: The absolute position of the mouse.
	Param ticks: The amount of ticks moved on the wheel.
	Param bounds: A bounding box enclosing the entire control.
	"""
		pass
	
	virtual def OnMouseDown(position as Vector,
	                        code as int,
	                        bounds as Rect):
	"""
	Respond to a mouse button being pressed.
	Param position: The absolute position of the mouse.
	Param code: A game-dependent code triggered by a mouse click.
	Param bounds: A bounding box enclosing the entire control.
	"""
		pass
	
	virtual def OnMouseUp(position as Vector,
	                      code as int,
	                      bounds as Rect):
	"""
	Respond to a mouse button being pressed.
	Param position: The absolute position of the mouse.
	Param code: A game-dependent code triggered by a mouse click.
	Param bounds: A bounding box enclosing the entire control.
	"""
		pass
	
	Parent:
	"""
	Access to the control that houses this control.
	Remarks:
		The value is null for top-level controls.
	"""
		get:
			return _parent
		protected set:
			_parent = value
	
	[IgnoreDisposal]
	private _parent as CompoundControl
	"""
	Access to the control that houses this control.
	Remarks:
		The value is null for top-level controls.
	"""










